package org.example.platerecognize.service;

import org.example.platerecognize.core.TorchPlateDetection;
import org.example.platerecognize.core.TorchPlateRecognition;

import java.nio.file.Path;

import static org.example.platerecognize.utils.CommonConst.RESOURCES_PATH;

public final class PlateExtractServiceFactory {

    private static PlateExtractService instance;

    /**
     * 创建service对象
     * @return
     */
    synchronized public static PlateExtractService getInstance() {
        if (instance==null) {
            Path path1 = Path.of(RESOURCES_PATH, "models/plate_detect.onnx");
            var torchPlateDetection = new TorchPlateDetection(path1.toString(), 1);

            Path path2 = Path.of(RESOURCES_PATH, "models/plate_rec_color.onnx");
            var torchPlateRecognition = new TorchPlateRecognition(path2.toString(), 1);

            instance = new PlateExtractService(torchPlateDetection, torchPlateRecognition);
        }

        return instance;
    }
}
